package com.minshenglife.zanzan.web.weixin;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.minshenglife.zanzan.service.BettingService;
import com.minshenglife.zanzan.service.SyncInfoService;
import com.minshenglife.zanzan.service.UserService;
import com.minshenglife.zanzan.web.weixin.service.WXBettingService;
import com.minshenglife.zanzan.web.weixin.service.WXWorkLogService;

/**
 * 定时器 执行批处理
 * @author huodd
 *
 */
@Controller
@RequestMapping("/timer")
public class TimerController {
	Logger log = LoggerFactory.getLogger(TimerController.class);
	@Resource
	BettingService bettingService;
	@Resource
	SyncInfoService syncService;
	@Resource
	WXBettingService wxBettingService;
	@Resource
	UserService userService;
	@Resource
	WXWorkLogService workLogService;
	/**
	 * 押宝批处理
	 * @param request
	 * @param response
	 */
	@RequestMapping("/batchBettingResult.timer")
    public void batchBettingResult(HttpServletRequest request, HttpServletResponse response){
		log.info("start batchBettingResult.timer ");
		bettingService.batchBettingResult();
		log.info("end batchBettingResult.timer ");
	}
	/**
	 * 同步部门批处理
	 * @param request
	 * @param response
	 */
	@RequestMapping("/batchSyncDeptInfo.timer")
    public void batchSyncDeptInfo(HttpServletRequest request, HttpServletResponse response){
		log.info("start batchSyncDeptInfo.timer ");
		syncService.syncDeptInfo();
		log.info("end batchSyncDeptInfo.timer ");
	}
	/**
	 * 同步员工批处理
	 * @param request
	 * @param response
	 */
	@RequestMapping("/batchSyncEmpInfo.timer")
    public void batchSyncEmpInfo(HttpServletRequest request, HttpServletResponse response){
		log.info("start batchSyncEmpInfo.timer");
		syncService.syncEmpInfo();
		log.info("end batchSyncEmpInfo.timer");
	}
	
	/**
	 * 每天9点前，将昨日的押宝结果发送给所有昨日参与押宝游戏的员工
	 * @param request
	 * @param response
	 */
	@RequestMapping("/batchSendFlowerKingResult.timer")
    public void batchSendFlowerKingResult(HttpServletRequest request, HttpServletResponse response){
		log.info("start batchSendFlowerKingResult.timer");
		wxBettingService.batchSendFlowerKingResult();
		log.info("end batchSendFlowerKingResult.timer");
	}
	
	/**
	 * 批处理执行 离职但没有解绑的用户 给解除绑定
	 */
	@RequestMapping("/batchLeaveAndNotUnbindEmpInfo.timer")
	public void batchLeaveAndNotUnbindEmpInfo(HttpServletRequest request, HttpServletResponse response){
		log.info("start batchLeaveAndNotUnbindEmpInfo.timer");
		userService.batchLeaveAndNotUnbindEmpInfo();
		log.info("end batchLeaveAndNotUnbindEmpInfo.timer");
	}
	
	/**
	 * 每天8点整，将：未填写前一个工作日日志的人员，推动一条信息：“早上好！您还未填写_月_日的工作日志，请尽快填写。”
	 * 组织资源部刘佳需求：date：20141010
	 * @param request
	 * @param response
	 */
	@RequestMapping("/batchSendPromptInfoOfWorkLog.timer")
    public void batchSendPromptInfoOfWorkLog(HttpServletRequest request, HttpServletResponse response){
		log.info("start batchSendFlowerKingResult.timer");
		workLogService.batchSendPromptInfoOfWorkLog();
		log.info("end batchSendFlowerKingResult.timer");
	}
}
